home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / GETLINE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-07  |  1.3 KB  |  72 lines

  1. #include <conio.h>
  2. #include <string.h>
  3. #include "tcclib.h"
  4.  
  5. int GetLine( char *ptr, int dsize, int start )
  6. {
  7.     register int ch;
  8.     register int j=start;
  9.     register int x;
  10.     register int i;
  11.     register int y;
  12.  
  13.     x = wherex();
  14.     y = wherey();
  15.     AtSay( x, y, ptr );
  16.     while (j <= dsize) {
  17.         gotoxy( x+j, y );
  18.         switch( ch = GComm() ){
  19.             case ESC:
  20.                 ptr[start] = '\0';
  21.                 return( -1 );
  22.             case CR:
  23.             case LF:
  24.                 return(strlen(ptr));
  25.             case BS:
  26.                 if ( j )
  27.                     j--;
  28.             case DEL:
  29.                 ch = strlen(ptr);
  30.                 for (i=j; i<ch; ++i)
  31.                     ptr[i] = ptr[i+1];
  32.                 gotoxy( x, y );
  33.                 Say( ptr );
  34.                 break;
  35.             case INS:
  36.                 for (i=strlen(ptr)+1; i>j; --i)
  37.                     ptr[i] = ptr[i-1];
  38.                 ptr[j] = ' ';
  39.                 gotoxy( x, y );
  40.                 Say( ptr );
  41.                 break;
  42.             case HOME:
  43.                 j = 0;
  44.                 break;
  45.             case END:
  46.                 j = strlen(ptr);
  47.                 break;
  48.             case LEFT:
  49.                 if (j) {
  50.                     j--;
  51.                 }
  52.                 break;
  53.             case RIGHT:
  54.                 if (j<dsize) {
  55.                     if (ptr[j] == '\0')
  56.                         ptr[j] = ' ';
  57.                     j++;
  58.                 }
  59.                 break;
  60.             default:
  61.                 if (j < dsize) {
  62.                     if ( ch >= 32 && ch <= 127 ) {
  63.                         ptr[j++] = ch;
  64.                         putch(ch);
  65.                     }
  66.                 }
  67.                 break;
  68.         }
  69.     }
  70.     return( 0 );
  71. }
  72.